from models import seckill
from . import Base
from .base import SnowFlakeIdModel
from sqlalchemy_serializer import SerializerMixin
from sqlalchemy import Column, ForeignKey, String, Integer, DateTime, Boolean,Enum,DECIMAL,BigInteger
from sqlalchemy.orm import relationship
from datetime import datetime
from .seckill import Seckill
import enum

class OrderStatusEnum(enum.Enum):
    UNPAYED = 1      # 未支付
    PAYED = 2        # 已支付
    TRANSIT = 3      # 运输中
    FINISHED = 4     # 已完成
    REFUNDING = 5    # 退款中
    REFUNDED = 6     # 已退款

class Order(Base,SnowFlakeIdModel, SerializerMixin):
    __tablename__ = 'order'
    serialize_only=("id","create_time", "status","count","amount","user_id", "address_id","seckill")
    create_time=Column(DateTime, default=datetime.now)
    status=Column(Enum(OrderStatusEnum),default=OrderStatusEnum.UNPAYED)
    count=Column(Integer)
    amount=Column(DECIMAL(10,2))
    user_id=Column(BigInteger)
    address=Column(String(500))
    seckill_id=Column(BigInteger,ForeignKey('seckill.id'))
    seckill=relationship(Seckill,backref='orders',lazy='select')
